﻿namespace td.Core.Xml
{
    using System;
    using System.Xml;

    public class PadXml : IXmlStorage
    {
      

        public string guid { get; set; }
        public string ShowAutoHideButton { get; set; }
        public string ShowCloseButton { get; set; }
        public string Title { get; set; }
        public string Class { get; set; }
        public string Icon { get; set; }
        public string Description { get; set; }


        public PadXml()
        {
            this.Class = "";
            this.Title = "";
            this.Icon = "";
            this.ShowAutoHideButton = "";
            this.ShowCloseButton = "";
            this.Description = "";
            this.guid = "";
        }

        public PadXml(string guid,string title, string icon, string classname)
        {
            this.Class = classname;
            this.Title = title;
            this.Icon = icon;
            this.guid = guid;
            this.ShowAutoHideButton = "True";
            this.ShowCloseButton = "False";
            this.Description = "";
            
        }

        public override bool Equals(object o)
        {
            if (o is PadXml)
            {
                PadXml xml = (PadXml)o;
                return (string.Equals(this.Class, xml.Class) && string.Equals(this.Title, xml.Title));
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public void GetValueFromXml(XmlNode objectNode)
        {
            if ((objectNode != null) && (string.Compare(objectNode.Name, "pad", true) == 0))
            {
                XmlAttributeCollection attributes = objectNode.Attributes;
                for (int i = 0; i < attributes.Count; i++)
                {
                    XmlAttribute attribute = attributes[i];
                    if (attribute.Name.ToLower().Equals("guid"))
                    {
                        this.guid = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("showautohidebutton"))
                    {
                        this.ShowAutoHideButton = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("showclosebutton"))
                    {
                        this.ShowCloseButton = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("title"))
                    {
                        this.Title = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("class"))
                    {
                        this.Class = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("icon"))
                    {
                        this.Icon = attribute.Value;
                    }
                    else if (attribute.Name.ToLower().Equals("description"))
                    {
                        this.Description = attribute.Value;
                    }
                    
                }
            }
        }

        public void SetValueToXml(XmlDocument xmldoc, XmlElement parentEle)
        {
            XmlElement newChild = xmldoc.CreateElement("Pad");
            newChild.SetAttribute("guid", this.guid);
            newChild.SetAttribute("ShowAutoHideButton", this.ShowAutoHideButton);
            newChild.SetAttribute("ShowCloseButton", this.ShowCloseButton);
            newChild.SetAttribute("Title", this.Title);
            newChild.SetAttribute("Class", this.Class);
            newChild.SetAttribute("Icon", this.Icon);
            newChild.SetAttribute("Description", this.Description);
            parentEle.AppendChild(newChild);
        }

        public override string ToString()
        {
            return ("[PadXml: " + this.Title + "]");
        }

    




     
    }
}

